package com.company.project.controller;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.entity.UserEntity;
import com.company.project.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Condition;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2024/06/19.
*/
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody UserEntity userEntity) {
        Condition condition = new Condition(UserEntity.class);
        condition.createCriteria().andEqualTo("name",userEntity.getName()).andEqualTo("password",userEntity.getPassword());
        List<UserEntity> users = userService.findByCondition(condition);
        if(!users.isEmpty()){
            ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator.genFailResult("用户名或密码错误");
        }
        return ResultGenerator.genSuccessResult();
    }
}
